<template>
	<view class="container">
		<view class="cu-form-group border-b" @click="UpdateClient">
			<view class="title">检测更新</view>
			<view class="text">{{Refresh}}</view>
			<view class="m-icon arrow"></view>
		</view>
		<view class="cu-form-group border-b" @click="Clear_Cache">
			<view class="title">清除缓存</view>
			<view class="text">{{Size}}</view>
			<view class="m-icon arrow"></view>
		</view>
		<view class="cu-form-group border-b" @click="About">
			<view class="title">关于我们</view>
			<view class="text"></view>
			<view class="m-icon arrow"></view>
		</view>
		<view class="btn">
			<view class="sure btnactive" @click="Exit">退出登录</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Refresh:'',
				Size:'',
				Version:'',
				VersionCode:0,
				WgtCode:0
			}
		},
		onPullDownRefresh() {

		},
		onShow() {
			this.WgtCode=uni.getStorageSync("WgtCode");
		},
		onLoad(options) {
			this.Calc_Size();
			this.Get_Version();
			this.Init_Refresh();
		},
		methods: {
			About(){
				uni.navigateTo({
					url:'about'
				})
			},
			UpdateClient(){
				this.Util.Toast("当前已是最新版本");return;
				this.Util.UpdateClient(true);
			},
			Get_Version(){
				plus.runtime.getProperty(plus.runtime.appid,(wgtinfo)=>{
					this.Version=wgtinfo.version;
					this.VersionCode=wgtinfo.versionCode;
				});
			},
			Init_Refresh(){
				var data = {};
				data.Act="Update_Client";
				this.Util.Post(data, json=>{
					if(json.State){
						if(json.Data.VersionCode>this.VersionCode){
							this.Refresh="有新版本可更新";
						}else{
							this.Refresh="已是最新版本";
						}
					}
				});
			},
			Calc_Size(){
				var size=0;
				uni.getSavedFileList({
				  success: res=> {
				    res.fileList.forEach(item=> {
				       size+=item.size;
				    });
					this.Size=size.ToSize();
				  }
				});
			},
			Clear_Cache(){
				this.Util.Confirm("你确定要清除缓存吗？", ()=>{
					uni.getSavedFileList({
					  success:res=> {
					    res.fileList.forEach(item=> {
					      uni.removeSavedFile({
					        filePath: item.filePath,
					        complete: obj=> {
					           this.Util.Toast("成功清除缓存："+this.Size, json=>{
								   this.Size='';
							   });
					        }
					      });
					    });
						if(res.fileList.length==0){
							this.Util.Toast("成功清除缓存");
							this.Size='';
						}
					  }
					});
				});
			},
			Exit(){
				var that=this;
				this.Util.Confirm("你确定要退出吗？",function(){
					uni.setStorageSync("Token","");
					uni.reLaunch({
						url:"/pages/index/login"
					})
				});
			}
		}
	}
</script>

<style lang="scss">
	.container{padding-top:30rpx;
		.text{color:$uni-tip-color; text-align: right;}
		.arrow{width:30rpx; height:100rpx; background-image: url(/static/arrow.png); background-position: center center; background-repeat: no-repeat; background-size: 30rpx;}
		.btn{width:100%; padding:30rpx; padding-top:300rpx; background-color: #f7f7f7;}
		.sure{width:100%; height:90rpx; line-height: 90rpx; border-radius:8rpx; text-align:center; background:#ef0223; color:#ffffff; font-size:34rpx;}
		.btnactive:active{opacity: 1; background:#fd2845 !important;}
	}
</style>
